<script type="text/html" template>
    <link rel="stylesheet" href="{{ layui.setter.base }}style/login.css?v={{ layui.admin.v }}-1" media="all">
</script>
<style>
    .layui-layout-body {
        width: 100%;
        height: 100%;
        background: url(../dist/img/Login.jpg)no-repeat center center;
        background-size: 100%;
        position: relative;
    }

    .title-STYLE {
        position: absolute;
        top: 230px;
        left: 58%;
        font-size: 24px;
        color: #FEFEFF;
        font-weight: 500;
    }

    .logonBten {
        background: #436BE4;
    }

    .login_title_base {
        font-size: 13px;
        color: #1F1F1F;
        text-align: center;
    }
</style>

<div class="layadmin-user-login layadmin-user-display-show" id="LAY-user-login" style="display: none;">
    <div class="title-STYLE">联创EAM后台管理系统</div>

    <div
        style="background: white;box-shadow: 0px 0px 8px #C2C2C2;width: 365px;height: 231px;right: 19%;top: 280px;position: absolute;border-radius: 2px;">
        <div class="layadmin-user-login-box layadmin-user-login-body layui-form">
            <div class="layui-form-item">
                <h2 class="login_title_base">账号登录</h2>
            </div>
            <div class="layui-form-item">
                <label class="layadmin-user-login-icon layui-icon layui-icon-username"
                    for="LAY-user-login-username"></label>
                <input type="text" name="userName" id="LAY-user-login-username" lay-verify="required" placeholder="用户名"
                    class="layui-input">
            </div>
            <div class="layui-form-item">
                <label class="layadmin-user-login-icon layui-icon layui-icon-password"
                    for="LAY-user-login-password"></label>
                <input type="password" name="password" id="LAY-user-login-password" lay-verify="required"
                    placeholder="密码" class="layui-input">
            </div>
            <div class="layui-form-item">
                <button class="logonBten layui-btn layui-btn-fluid" lay-submit
                    lay-filter="LAY-user-login-submit">登入</button>
            </div>
        </div>
    </div>
</div>


<script>
    layui.use(['admin', 'form', 'user', 'api', 'utill'], function () {
        var $ = layui.$,
            setter = layui.setter,
            admin = layui.admin,
            form = layui.form,
            router = layui.router(),
            api = layui.api,
            utill = layui.utill,
            search = router.search;
            form.render();
            utill.keyup('document','.logonBten')
            utill.keyup('#LAY-user-login-password','.logonBten')
                  //提交
        form.on('submit(LAY-user-login-submit)', function (obj) {
            //请求登入接口
            admin.req({
                url: api.host + api.login,
                data: obj.field,
                type: "POST",
                success: function (res) {
                    if(res.code == -1){
                        $('#LAY-user-login-password').blur();
                    }else{
                        utill.setCookie('userName', res.data.user.userName);
                        utill.setCookie('token',res.data.token);
                        utill.setCookie('ipay-merchant',JSON.stringify(res.data.user));
                        layui.sessionData(setter.tableName, {
                            key: setter.request.tokenName,
                            value: res.data.token
                        });
                        layui.sessionData(setter.tableName, {
                            key: setter.request.userInfo,
                            value: res.data.user
                        });
                    // 登入成功的提示与跳转
                        layer.msg('登入成功', {
                            offset: '15px',
                            icon: 1,
                            time: 1000
                        }, function () {
                            location.hash = search.redirect ? decodeURIComponent(search.redirect) : '/home/balance';
                        });
                    }
                }
            });
        });
    });
</script>